using System.Collections.Generic;
/// <summary>
/// AbsHFMetaObject【IHFSerializable接口】
/// </summary>
public partial class AbsHFMetaObject : IHFSerializable
{
    #region IHFISerializable    
    /// <summary>
    /// 导出序列化数据
    /// </summary>
    /// <returns>序列化数据</returns>
    public List<byte> ExportSerializable()
    {
        List<byte> sers = new List<byte>();
        sers.AddRange(mGlobalId.HFToBytes());
        OnBeforeExportSerializable(this, sers);
        byte[] bytes = OnExportSerializable();
        if (bytes != null && bytes.Length > 0)
        {
            sers.AddRange(bytes);
        }
        OnAfterExportSerializable(this, sers);        
        return sers;
    }
    /// <summary>
    /// 导出序列化之前事件处理
    /// </summary>
    /// <param name="_self">序列化对象</param>
    /// <param name="_bytes">序列化数据</param>
    protected virtual void OnBeforeExportSerializable(IHFSerializable _self, List<byte> _bytes) { }

    /// <summary>
    /// 导出序列化数据
    /// </summary>
    /// <returns>序列化数据</returns>
    protected virtual byte[] OnExportSerializable() { return new byte[0]; }

    /// <summary>
    /// 导出序列化之后事件处理
    /// </summary>
    /// <param name="_self">序列化对象</param>
    /// <param name="_bytes">序列化数据</param>
    protected virtual void OnAfterExportSerializable(IHFSerializable _self, List<byte> _bytes) { }

    /// <summary>
    /// 导入序列化数据
    /// </summary>
    /// <param name="_data">序列化数据</param>
    /// <param name="_startIndex">起始索引</param>
    /// <returns>结束索引</returns>
    public int ImportSerializable(byte[] _data, int _startIndex)
    {
        mGlobalId = _data.HFToInt32(ref _startIndex);
        OnBeforeImportSerializable(this, _data, _startIndex);        
        _startIndex = OnImportSerializable(_data, _startIndex);
        OnAfterImportSerializable(this, _data, _startIndex);
        return _startIndex;
    }

    /// <summary>
    /// 导入序列化之前事件处理
    /// </summary>
    /// <param name="_self">序列化对象</param>
    /// <param name="_bytes">序列化数据</param>
    /// <param name="_startIndex">起始索引</param>
    protected virtual void OnBeforeImportSerializable(IHFSerializable _self, byte[] _bytes, int _startIndex) { }

    /// <summary>
    /// 导入序列化数据
    /// </summary>
    /// <param name="_data">序列化数据</param>
    /// <param name="_startIndex">起始索引</param>
    /// <returns>结束索引</returns>
    protected virtual int OnImportSerializable(byte[] _data, int _startIndex) { return _startIndex; }

    /// <summary>
    /// 导入序列化之后事件处理
    /// </summary>
    /// <param name="_self">序列化对象</param>
    /// <param name="_bytes">序列化数据</param>
    /// <param name="_startIndex">起始索引</param>
    protected virtual void OnAfterImportSerializable(IHFSerializable _self, byte[] _bytes, int _startIndex) { }
    #endregion
}
